#' Relative strength index
#'
#' @param period rolling window period
#' @param type type of the moving average
#'
#' @return a stateful function
#' @export
#'
new_rsi <- function(period, type = c("ema", "dema", "tema", "t3ma", "ewma","zlema",
                                     "tma", "wma", "hma", "vwma", "evwma", "tsi"))
{
  type <- match.arg(type)
  switch(type,
         ema   = mk_online_func_x("rsi_ema", period),
         dema  = mk_online_func_x("rsi_dema", period),
         tema  = mk_online_func_x("rsi_tema", period),
         t3ma  = mk_online_func_x("rsi_t3ma", period),
         ewma  = mk_online_func_x("rsi_ewma", period),
         zlema = mk_online_func_x("rsi_zlema", period),
         tma   = mk_online_func_x("rsi_tma", period),
         wma   = mk_online_func_x("rsi_wma", period),
         hma   = mk_online_func_x("rsi_hma", period),
         vwma  = mk_online_func_xw("rsi_vwma", period),
         evwma = mk_online_func_xw("rsi_evwma", period),
         tsi   = mk_online_func_x("rsi_tsi", period))
}

#' RSI of MA oscillator
#'
#' @param fast_period fast rolling window period
#' @param slow_period slow rolling window period
#' @param signal_period signal rolling window period
#' @param type type of the moving average
#'
#' @return a stateful function
#' @export
#'
new_rsi_maosc <- function(fast_period, slow_period, signal_period,
                          type = c("ema", "dema", "tema", "t3ma", "ewma", "zlema",
                                   "tma", "wma", "hma", "vwma", "evwma"))
{
  type <- match.arg(type)
  switch(type,
         ema   = mk_online_func_x("rsi_emosc", fast_period, slow_period, signal_period),
         dema  = mk_online_func_x("rsi_demosc", fast_period, slow_period, signal_period),
         tema  = mk_online_func_x("rsi_temosc", fast_period, slow_period, signal_period),
         t3ma  = mk_online_func_x("rsi_t3mosc", fast_period, slow_period, signal_period),
         ewma  = mk_online_func_x("rsi_ewmosc", fast_period, slow_period, signal_period),
         zlema = mk_online_func_x("rsi_zlemosc", fast_period, slow_period, signal_period),
         tma   = mk_online_func_x("rsi_tmosc", fast_period, slow_period, signal_period),
         wma   = mk_online_func_x("rsi_wmosc", fast_period, slow_period, signal_period),
         hma   = mk_online_func_x("rsi_hmosc", fast_period, slow_period, signal_period),
         vwma  = mk_online_func_xw("rsi_vwmosc", fast_period, slow_period, signal_period),
         evwma = mk_online_func_xw("rsi_evwmosc", fast_period, slow_period, signal_period))
}
